(function() {
  "use strict";
  var $, Backbone, HeadUserInfo, HotelDetailComment, HotelDetailCommentModel, HotelDetailMap, HotelDetailRoom, HotelDetailRoomBase, HotelDetailRoomBaseModel, HotelDetailRoomModel, HotelDetailRoomOversea, HotelDetailRoomOverseaModel, HotelError, HotelListFilterModel, HotelListFilterView, HotelListHotels, HotelListHotelsList, HotelListHotelsListBase, HotelListHotelsListOversea, HotelListHotelsListSale, HotelListHotelsModel, HotelListHotelsPage, HotelListHotelsSort, HotelListMap, HotelLoading, HotelMapBase, HotelUserInfo, HotelUserSignInPopup, TrackCompatibleMode, _, __hotelDetailRoomDepend, __hotelDetailRoomModel, __hotelDetailRoomTemplate, __hotelDetailRoomView, __hotelListHotelsDependTemplates, __hotelListHotelsList, __hotelListRoomType, _func, _n, _stor, _vars;

  _ = this['_'];

  $ = this['jQuery'] || this['Zepto'];

  Backbone = this['Backbone'];

  this.N = this.ndoo || (this.ndoo = {});

  _n = this.ndoo;

  _vars = _n.vars;

  _func = _n.func;

  _stor = _n.storage;


  /*[ui.checktindate]{{{ */

    _n.block('ui.checkinDate', {
      maxCheckinDays: 60,
      convertDate: function(date) {
        var dateMatch;
        dateMatch = date.match(/^(\d{2,4})-(\d{1,2})-(\d{1,2})$/);
        return date = new Date(new Number(dateMatch[1]), new Number(dateMatch[2]) - 1, new Number(dateMatch[3]));
      },
      dateAddDay: function(date, add) {
        var dateObj;
        if (typeof date === 'string') {
          dateObj = this.convertDate(date);
        } else {
          dateObj = date;
        }
        return new Date(dateObj.getFullYear(), dateObj.getMonth(), dateObj.getDate() + add);
      },
      datepickerCheckDate: function(startDate, endDate) {
        var _self, absToMaxData, checkin, checkinMatch, checkout, currDate, fenge, frommaxDate, fromminDate, newcheckout, newcheckoutday, newcheckoutmonth, newcheckoutyear, tomaxDate, tominDate;
        _self = this;
        checkin = startDate.val();
        checkout = endDate.val();
        fromminDate = new Date();
        currDate = $(startDate).data('date');
        if (currDate) {
          fromminDate = _self.convertDate(currDate);
        }
        frommaxDate = _self.dateAddDay(fromminDate, 89);
        absToMaxData = _self.dateAddDay(fromminDate, 90);
        tominDate = _self.dateAddDay(fromminDate, 1);
        tomaxDate = _self.dateAddDay(fromminDate, _self.maxCheckinDays);
        startDate.datepicker({
          numberOfMonths: 2,
          defaultDate: checkin,
          constrainInput: true,
          dateFormat: 'yy-mm-dd',
          beforeShow: function(input, inst) {

          },
          onSelect: function(selectedDate) {
            var tomaxDate, absToMaxData;
            $(endDate).datepicker('option', 'minDate', _self.dateAddDay(selectedDate, 0));
            $(this).data('select', 'selected');
          },
          onClose: function() {
            var checkIn, checkInDate;
            if ($(this).data('select') === 'selected') {
              $(endDate).focus();
              $(this).data('select', '');
            }
            checkIn = startDate.val();
            checkInDate = _self.convertDate(startDate.val());
            _n.trigger('checkindateChoice', {
              checkIn: checkIn,
              checkInDate: checkInDate
            });
          }
        });
        endDate.datepicker({
          numberOfMonths: 2,
          dateFormat: 'yy-mm-dd',
          constrainInput: true,
          beforeShow: function(input, inst) {

          },
          onSelect: function(selectedDate) {

          },
          onClose: function() {
            _n.trigger('clearActiveClassName');
            return _n.trigger('checkoutdataChoice');
          }
        });
        if ($(startDate).parents('.container').hasClass('newIndex')) {
          startDate.datepicker('option', 'buttonText', checkin);
        }
        if ($(endDate).parents('.container').hasClass('newIndex')) {
          newcheckoutyear = tominDate.getFullYear();
          newcheckoutmonth = tominDate.getMonth() + 1 < 10 ? '0' + (tominDate.getMonth() + 1) : tominDate.getMonth() + 1;
          newcheckoutday = tominDate.getDate() < 10 ? '0' + tominDate.getDate() : tominDate.getDate();
          fenge = '-';
          newcheckout = newcheckoutyear + fenge + newcheckoutmonth + fenge + newcheckoutday;
          endDate.datepicker('option', 'buttonText', newcheckout);
        }
      },
      themes: function(brand) {
        var themeColor;
        themeColor = {
          main: 'ae1363'
        };
        return $('<style>.ui-datepicker .ui-state-active{background-color:#' + themeColor[brand] + '!important;}</style>').appendTo($('head'));
      },
      depend: 'jquery.datepicker',
      init: function(elem, params) {
        var $elem, end, start;
        params = _func.formatUrlParam(params);
        params.brand && this.themes(params.brand);
        $elem = $(elem);
        this.checkindateDom = $elem.find('.checkInDate');
        this.checkoutdateDom = $elem.find('.checkOutDate');
        params.brand && (this.brand = params.brand);
        start = $elem.find('.checkindate');
        end = $elem.find('.checkoutdate');
        this.datepickerCheckDate(start, end);
      }
    });



  /*}}} */


  /*[HotelMapBase] 地图基础View{{{ */

  HotelMapBase = Backbone.View.extend({
    data: null,
    markers: {},
    active: null,
    zoom: 16,
    renderMap: function(lat, lng) {
      var mapOption;
      mapOption = {
        lat: lat,
        lng: lng,
        zoom: this.zoom
      };
      this.$mapbox = this.$('.mapbox');
      this.map = new _n.util.map(this.$mapbox.get(0), mapOption, _vars.mapRenderType);
      if (_n.pageId.indexOf('overseaOrderMap') > 1) {
        _n.trigger('mapLoadedSuccess', this.map);
      }
      if (this.map.type === 'amap') {
        this.$mapbox.find('.amap-logo, .amap-copyright').hide();
      }
    },
    render: function(hotelId, hotelName, hotelStyle, lat, lng) {
      this.renderMap(lat, lng);
      this.addHotelBrandMarker(hotelId, hotelName, hotelStyle, lat, lng);
      this.trigger('renderSuccess');
    },
    setCenter: function(lat, lng) {
      var map;
      map = this.map.getMap();
      map.setCenter(this.map.setLatLng(lat, lng));
    },
    setCenterWithAnimation: function(lat, lng, marker) {
      var map;
      map = this.map.getMap();
      this.map.moveMapByLatLng(lat, lng);
      return this.active && this.map.markerAnimation(marker);
    },
    setActiveMarker: function(hotelId, lat, lng) {
      var marker;
      if (marker = this.markers[this.active]) {
        this.map.markerActive(marker, false);
      }
      if (marker = this.markers[hotelId]) {
        this.map.markerActive(marker, true);
        this.setCenterWithAnimation(lat, lng, marker);
        return this.active = marker;
      }
    },
    addHotelBrandMarker: function(hotelId, hotelName, hotelStyle, lat, lng) {

      /*设置居中 */
      var marker, markerIconOption;
      if (!this.markers[hotelId]) {
        markerIconOption = _func.getHotelStyleMarkIcon(hotelStyle, 'list');
        _.extend(markerIconOption, {
          lat: lat,
          lng: lng
        });
        marker = this.map.addIconMarker(markerIconOption);
        marker.setTitle(hotelName);
        this.markers[hotelId] = marker;
      }
      this.setActiveMarker(hotelId, lat, lng);
    },
    runTask: function() {
      this.showHotelMap(this.data.hotelId, this.data.hotelName, this.data.hotelStyle, this.data.lat, this.data.lng);
    },
    showHotelMap: function(hotelId, hotelName, hotelStyle, lat, lng) {
      if (!_func.checkMapInstall()) {
        if (!this.data) {
          this.data = {
            hotelId: hotelId,
            hotelName: hotelName,
            hotelStyle: hotelStyle,
            lat: +lat,
            lng: +lng
          };
          _n.on('mapInstall', (function(_this) {
            return function() {
              return _this.runTask();
            };
          })(this));
        } else {
          this.data = {
            hotelId: hotelId,
            hotelName: hotelName,
            hotelStyle: hotelStyle,
            lat: lat,
            lng: lng
          };
        }
      } else {
        if (!this.map) {
          this.render.apply(this, arguments);
        } else {
          this.addHotelBrandMarker.apply(this, arguments);
        }
      }
    }
  });


  /*}}} */


  /*[HotelListMap] 酒店列表地图 {{{ */

  HotelListMap = HotelMapBase.extend({
    constructor: function(option) {
      if (option) {
        _.extend(this, option);
      }
      if (this.events) {
        this.delegateEvents();
      }
      if (!_func.checkMapInstall()) {
        _func.mapInstall();
      }
      _n.on('hotelListMapChange', (function(_this) {
        return function() {
          _this.showHotelMap.apply(_this, arguments);
        };
      })(this));
      _n.on('removeMarkers', (function(_this) {
        return function() {
          var self;
          self = _this;
          self.map && self.map.removeMarkers(self.markers, true);
          self.markers = {};
          return self.active = null;
        };
      })(this));
    }
  });

  _n.block('block.hotelListMap', {
    depend: ['ndoo_util'],
    init: function(elem, params) {
      return new HotelListMap({
        el: elem,
        $el: $(elem)
      });
    }
  });


  /*}}} */


  /*[HotelDetailMap] 酒店详情地图{{{ */

  HotelDetailMap = HotelMapBase.extend({
    renderSuccess: function() {
      var _map;
      if (_vars.mapRenderType === 'amap') {
        _map = this.map.getMap();
        _map.setStatus({
          'scrollWheel': false
        });
        _map.plugin(['AMap.ToolBar'], function() {
          var toolBar;
          toolBar = new AMap.ToolBar;
          _map.addControl(toolBar);
        });
      }
    },
    zoom: 14,
    constructor: function(option) {
      if (option) {
        _.extend(this, option);
      }
      if (this.events) {
        this.delegateEvents();
      }
      if (!_func.checkMapInstall()) {
        _func.mapInstall();
      }
      _n.on('hotelDetailMap', (function(_this) {
        return function() {
          _this.showHotelMap.apply(_this, arguments);
        };
      })(this));
      this.on('renderSuccess', this.renderSuccess);
    }
  });

  _n.block('block.hotelDetailMap', {
    depend: ['ndoo_util'],
    init: function(elem, params) {
      return new HotelDetailMap({
        el: elem,
        $el: $(elem)
      });
    }
  });


  /*}}} */


  /*[block.backToTop] 返回顶部{{{ */

  _n.block('block.backToTop', function(elem, params) {
    var $elem, scrollHandler;
    $elem = $(elem);
    $elem.on('mouseenter', '.item', function(e) {
      var $self;
      $self = $(this);
      if (!$self.hasClass('back')) {
        $self.addClass('active');
      }
      if ($self.hasClass('scan')) {
        $self.siblings('.scanbox').fadeIn();
      }
    }).on('mouseleave', '.item', function(e) {
      var $self;
      $self = $(this);
      if (!$self.hasClass('back')) {
        $self.removeClass('active');
      }
      if ($self.hasClass('scan')) {
        $self.siblings('.scanbox').hide();
      }
    }).on('click', '.back', function(e) {
      _func.setScrollTop(0);
    });
    scrollHandler = function(e) {
      var doc, height, top;
      doc = document;
      top = Math.max(doc.body.scrollTop, doc.documentElement.scrollTop);
      height = Math.min(doc.body.clientHeight, doc.documentElement.clientHeight);
      if (top > height) {
        $elem.show();
      } else {
        $elem.hide();
      }
    };
    scrollHandler();
    $(window).on('scroll', scrollHandler);
  });


  /* }}} */
  /*[ui.checkAddress] 省市区数据模型{{{ */
  var checkAddressModel = Backbone.Model.extend({
    defaults: {
      cityList: [],
      provinceList: []
    },
    constructor: function(){
      Backbone.Model.apply(this, arguments);
    },
    ajaxCallback: function(options) {
      var self = this;
      $.ajax({
        url: options['url'],
        type: 'POST',
        dataType: 'json',
        contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
        data: options['param'],
        beforeSend: function(){

        },
        success: function(chunk){
      	if(chunk.Result){
          if(options['url'] === '/CompanyCardSubmit/GetProvinceCode'){
            self.set('provinceList', chunk.Data);
          } else {
            self.set('cityList', chunk.Data);
          }
      	}
        },
        error: function(chunk){

        }
      });
    },
    fetchData: function(objParam){
      var options = {
        param: {}
      };
      options['param']['__RequestVerificationToken'] = $('[name="__RequestVerificationToken"]').val();
      if(objParam.type === 'province'){
        options['url'] = '/CompanyCardSubmit/GetProvinceCode';
        this.ajaxCallback(options);
      } else if(objParam.type !== 'city') {
        options['url'] = '/CompanyCardSubmit/GetCityCodeByProvinceCode';
        options['param']['ProvinceCode'] = objParam['ProvinceCode'];
        this.ajaxCallback(options);
      }
    }
  });
  /* }}} */
  var checkAddress = Backbone.View.extend({
    checkCityHandler: function(e){
      if(this.params === 'city'){
        if(this.$el.find('.check-province .list li').length === 0){
          return;
        }
      }
      if(this.$el.hasClass('active')){
        this.$el.removeClass('active').find('.check-province').css('display', 'none');
      } else {
        if(this.$el.find('.check-province .list li').length > 4){
          this.$el.addClass('active').find('.check-province').css({'display': 'block', 'overflow-x': 'hidden', 'overflow-y': 'auto', 'height': '200px'});
        } else {
          this.$el.addClass('active').find('.check-province').css({'display': 'block', 'overflow': 'hidden', 'height': '100px'});
        }
      }
    },
    cityItemOverHandler: function(e){
      var $target = $(e.target);
      if($target.hasClass('active')){
        return;
      } else {
        $target.addClass('active');
      }
      this.$el.find('.check-province .sitem').not($target).removeClass('active');
    },
    cityItemClickHandler: function(e){
      var $target = $(e.target),
        text = $target.text(),
        $elem = this.$el;
      this.$el.removeClass('active').find('.check-province').css('display', 'none').find('.sitem').removeClass('active');
      if(this.params === 'province'){
        this.$el.find('.select1').data('provinceCode', $target.data('provinceCode')).val(text);
      } else {
        this.$el.find('.select1').data('cityCode', $target.data('cityCode')).val(text);  
      }
      if(this.params === 'province'){
        var listStr = '',
          $citySelect = $elem.next();
        this.model.fetchData({type: '', ProvinceCode: $target.data('provinceCode')});
        this.listenTo(this.model, 'change:cityList', _.bind(function(){
          var cityList = this.model.get('cityList');
          $.each(cityList, function(index, item){
            if(listStr === ''){
              listStr = '<li class="">'
                      + '<a class="sitem" data-city-code="' + item.CityCode + '" >'
                      + item.CityName
                      + '</a></li>';
            } else {
              listStr += '<li class="">'
                      + '<a class="sitem" data-city-code="' + item.CityCode + '" >'
                      + item.CityName
                      + '</a></li>';
            }
          });
          $citySelect.find('.select1').val('');
          $citySelect.find('.check-province .list').html(listStr);
        }, this))
        if($citySelect.hasClass('active')){
          $citySelect.removeClass('active');
          $citySelect.find('.check-province').css('display', 'none');
        }
      }
    },
    events: {
      'click .select1,.arrowbox' : 'checkCityHandler',
      'mouseenter .check-province .sitem' : 'cityItemOverHandler',
      'click .check-province .sitem' : 'cityItemClickHandler'
    },
    constructor: function(option){
      Backbone.View.apply(this, arguments);
      this.params = option['params'];
      var $elem = this.$el;
      this.model.fetchData({type: this.params});
      this.listenTo(this.model, 'change:provinceList', _.bind(function(){
        if(this.params === 'province'){
          var cityList = this.model.get('provinceList'),
            listStr = '';
          $.each(cityList, function(index, item){
            if(listStr === ''){
              listStr = '<li class="">'
                      + '<a class="sitem" data-province-code="' + item.ProvinceCode + '" >'
                      + item.ProvinceName
                      + '</a></li>';
            } else {
              listStr += '<li class="">'
                      + '<a class="sitem" data-province-code="' + item.ProvinceCode + '" >'
                      + item.ProvinceName
                      + '</a></li>';
            }
          });
          $elem.find('.check-province .list').html(listStr);
        }
      }, this));
    }
  });
  /*[ui.checkAddress] 省市区选择{{{ */
  _n.block('ui.checkAddress', {
    init: function(elem, params){
      return new checkAddress({
        el: elem,
        $elem: $(elem),
        params: params,
        model: new checkAddressModel()
      });
    }
  });
  /* }}} */

  /*[ui.wideScreenAdapter] ie下宽窄屏适配{{{ */

  _n.block('ui.wideScreen', function(elem, params) {
    var $elem, $html, resizeHandler, screenWidth;
    $elem = $(elem);
    screenWidth = screen.availWidth;
    if (screenWidth < 1200) {
      return;
    }
    $html = $('html');
    if (!$html.hasClass('ltie9')) {
      return;
    }
    resizeHandler = function(e) {
      var width;
      width = document.body.clientWidth;
      if (width > 1200) {
        $('html').addClass('Cwidescreen');
      } else {
        $('html').removeClass('Cwidescreen');
      }
    };
    resizeHandler();
    $(window).on('resize', resizeHandler);
  });


  /*}}} */


  /*[block.hotelDetailComment] 酒店详情页评论模型{{{ */

  HotelDetailCommentModel = Backbone.Model.extend({
    defaults: {
      commentData: null,
      pageIndex: 1
    },
    ajaxCallback: function(mapNewPropId, xhr, status) {
      var currMapNewPropId;
      if (_func.checkSuccessStatus(xhr.status)) {
        currMapNewPropId = _stor('detailCommentMapNewPropId');
        if (currMapNewPropId === mapNewPropId) {
          if (xhr.responseJSON) {
            this.set('commentData', xhr.responseJSON);
          } else if (xhr.responseText) {
            this.set('commentData', $.parseJSON(xhr.responseText));
          }
        }
      }
    },
    fetchComment: function(PageIndex, MapPropId) {
      var HotelId, PageSize, urlParam;
      this.set('pageIndex', PageIndex);
      PageSize = _vars.detailCommentPageSize;
      HotelId = _vars.hotelId;
      urlParam = {
        HotelId: HotelId,
        PageIndex: PageIndex,
        PageSize: PageSize
      };
      if (MapPropId) {
        urlParam.MapPropId = MapPropId;
        _func.getAjaxData(_vars.getHotelPropReview, _.bind(this.ajaxCallback, this, MapPropId), {
          data: urlParam
        });
      } else {
        _func.getAjaxData(_vars.getHotelCommentUrl, _.bind(this.ajaxCallback, this, MapPropId), {
          data: urlParam
        });
      }
    }
  });


  /*}}} */


  /*[HotelDetailComment] 酒店详情评论{{{ */

  HotelDetailComment = Backbone.View.extend({
    renderFullComment: function(data) {
      var DefaultUserPhoto, IsFull, LoadImg, PageHtml, PageSize, html;
      if (!data.TotalCount && data.totalCount) {
        data.TotalCount = data.totalCount;
      }
      DefaultUserPhoto = _vars.defaultUserPhoto54x54;
      PageSize = _vars.detailCommentPageSize;
      IsFull = true;
      LoadImg = _vars.loadImg80x34;
      PageHtml = this.getPageHtml(data);
      data = _.extend(data, {
        DefaultUserPhoto: DefaultUserPhoto,
        PageSize: PageSize,
        IsFull: IsFull,
        PageHtml: PageHtml,
        LoadImg: LoadImg
      });
      html = this.template(data);
      this.$el.html(html);
      this.$el.find('.pages').css('height', 87);
    },
    setCommentHeight: function(set) {
      var $commentbox, height;
      $commentbox = this.$('.commentbox');
      if (set) {
        height = $commentbox.height();
        return $commentbox.css('min-height', height);
      } else {
        return $commentbox.css('min-height', 'auto');
      }
    },
    renderComment: function(commentData) {
      var DefaultUserPhoto, LoadImg, PageSize, html;
      if (!commentData) {
        commentData = this.model.get('commentData');
      }
      DefaultUserPhoto = _vars.defaultUserPhoto54x54;
      PageSize = _vars.detailCommentPageSize;
      LoadImg = _vars.loadImg80x34;
      commentData = _.extend(commentData, {
        DefaultUserPhoto: DefaultUserPhoto,
        PageSize: PageSize,
        LoadImg: LoadImg
      });
      this.setCommentHeight(!commentData.CommentList.length);
      html = this.template(commentData);
      this.$('.commentbox').html(html);
      this.renderPage(commentData);
    },
    getPageHtml: function(commentData) {
      var data, pageCount, pageHtml, pageIndex, pageSize;
      pageIndex = this.model.get('pageIndex') || 1;
      if (!commentData) {
        commentData = this.model.get('commentData');
      }
      if (commentData.TotalCount > 0) {
        pageSize = _vars.detailCommentPageSize;
        pageCount = Math.ceil(commentData.TotalCount / parseInt(pageSize));
        data = {
          FirstIndex: 1,
          UpIndex: pageIndex < 3 ? 1 : pageIndex - 1,
          CurrentIndex: pageIndex,
          DownIndex: pageIndex > pageCount - 2 ? pageCount : pageIndex + 1,
          LastIndex: pageCount
        };
        pageHtml = _func.renderTemplate('HotelCommonPage', data);
        return _func.trimHtmlSpace(pageHtml);
      } else {
        return '';
      }
    },
    renderPage: function(commentData) {
      var html;
      html = this.getPageHtml(commentData);
      this.$('.Cpage').html(html);
    },
    renderLoading: function() {
      this.renderComment({
        CommentList: [],
        LoadImg: _vars.loadImg80x34
      });
      this.$('.pages').css('visibility', 'hidden');
    },
    pageHandler: function(e) {
      var $self, MapNewPropId, page;
      $self = $(e.currentTarget);
      if (!$self.hasClass('active')) {
        page = $self.data('pageIndex');
        MapNewPropId = _stor('detailCommentMapNewPropId');
        this.renderLoading();
        this.model.fetchComment(page, MapNewPropId);
      }
      return false;
    },
    keyHandler: function(e) {
      var $self, MapNewPropId, page;
      $self = $(e.currentTarget);
      if (!$self.hasClass('active')) {
        $self.siblings('.active').removeClass('active');
        $self.addClass('active');
        page = 1;
        MapNewPropId = $self.data('mapNewPropId');
        _stor('detailCommentMapNewPropId', MapNewPropId, _stor.REWRITE);
        this.renderLoading();
        this.model.fetchComment(page, MapNewPropId);
      }
    },
    setAnchor: false,
    commentAnchor: function(e) {
      var $link, hash;
      if (!this.setAnchor) {
        this.setAnchor = true;
        hash = location.hash;
        if (hash.match(/^#comment$/)) {
          $link = $('#Pdetail_part2 .link[data-type=comment]');
          if ($link.length) {
            return $link.trigger('click');
          }
        }
      }
    },
    events: {
      'click .Cpage a': 'pageHandler',
      'click .keys span': 'keyHandler'
    },
    constructor: function(option) {
      if (option) {
        _.extend(this, option);
      }
      if (this.events) {
        this.delegateEvents();
      }
      this.template = _func.getTemplate('HotelDetailHotelComments');
      this.listenTo(this.model, 'change:commentData', _.bind(function() {
        this.$('.pages').css('visibility', 'visible');
        return this.renderComment();
      }, this));
      _n.on('detailRoomRenderFinish', _.bind(this.commentAnchor, this));
      if (_vars.hotelCommentListData && _vars.hotelCommentListData.TotalCount) {
        this.renderFullComment(_vars.hotelCommentListData);
        this.$el.removeClass('Ldn');
      }
    }
  });

  _n.block('block.hotelDetailComment', {
    depend: ['HotelDetailHotelCommentsTemplate'],
    init: function(elem, params) {
      return new HotelDetailComment({
        el: elem,
        $el: $(elem),
        model: new HotelDetailCommentModel()
      });
    }
  });


  /*}}} */


  /*[HotelListHotelsPage] 酒店列表分页{{{ */

  HotelListHotelsPage = Backbone.View.extend({
    refreshPage: function(totalCount) {
      var data, pageCount, pageIndex, pageSize;
      if (totalCount === void 0) {
        totalCount = _stor('hotelTotalCount');
      } else {
        _stor('hotelTotalCount', totalCount, _stor.REWRITE);
      }
      if (totalCount > 0) {
        pageIndex = HZWeb.search.getParam('PageIndex') || 1;
        pageSize = _vars.pageSize;
        pageCount = Math.ceil(totalCount / parseInt(pageSize));
        data = {
          FirstIndex: 1,
          UpIndex: pageIndex < 3 ? 1 : pageIndex - 1,
          CurrentIndex: pageIndex,
          DownIndex: pageIndex > pageCount - 2 ? pageCount : pageIndex + 1,
          LastIndex: pageCount
        };
        this.$el.html(_func.trimHtmlSpace(this.template(data)));
      } else {
        this.$el.html('');
      }
    },
    clearPage: function() {
      if (HZWeb.search.getParam('PageIndex') !== 1) {
        return HZWeb.search.setParam('PageIndex', 1);
      }
    },
    pageHandler: function(e) {
      var $self;
      $self = $(e.currentTarget);
      if (!$self.hasClass('active')) {
        HZWeb.search.setParam('PageIndex', $self.data('pageIndex'));
        _n.trigger('fetchHotelList', 'pageChange');
      }
      return false;
    },
    events: {
      'click a': 'pageHandler'
    },
    constructor: function(option) {
      if (option) {
        _.extend(this, option);
      }
      if (this.events) {
        this.delegateEvents();
      }
      this.template = _func.getTemplate('HotelCommonPage');
      _n.on('refreshPage', _.bind(this.refreshPage, this));
      _n.on('clearPage', _.bind(this.clearPage, this));
    }
  });


  /*}}} */


  /*[HotelListHotelsSort] 酒店列表排序{{{ */

  HotelListHotelsSort = Backbone.View.extend({
    clearSort: function() {
      var $active, Latitude, Longitude;
      $active = this.$('.active');
      Latitude = HZWeb.search.getParam('Latitude');
      Longitude = HZWeb.search.getParam('Longitude');
      if ($active.hasClass('sort')) {
        HZWeb.search.removeParam('SortBy');
        return this.$el.html(this.template({
          Latitude: Latitude,
          Longitude: Longitude
        }));
      }
    },
    sortHandler: function(e) {
      var $prev, $self, sort, type;
      $self = $(e.currentTarget);
      if (!$self.hasClass('active')) {
        $prev = $self.siblings('.active');
        if ($self.hasClass('sort')) {
          $prev.removeClass('active');
          $self.addClass('active');
          sort = $self.data('sort');
          HZWeb.search.setParam('SortBy', $self.data('type') + sort);
        } else {
          this.clearSort();
        }
        _n.trigger('fetchHotelList', 'sortChange');
      } else if ($self.hasClass('sort')) {
        type = $self.data('type');
        if (type !== 'Distance' && type !== 'CommentScore') {
          sort = $self.data('sort');
          if (sort === 'Desc') {
            sort = 'Asc';
            $self.attr('title', $self.data('titlePrefix') + '从低到高');
            $self.find('.Cicon').attr('class', 'Cicon sortup');
          } else {
            sort = 'Desc';
            $self.attr('title', $self.data('titlePrefix') + '从高到低');
            $self.find('.Cicon').attr('class', 'Cicon sortdown');
          }
          $self.data('sort', sort);
          HZWeb.search.setParam('SortBy', $self.data('type') + sort);
          _n.trigger('fetchHotelList', 'sortChange');
        }
      }
    },
    events: {
      'click .label': 'sortHandler',
      'click .sort': 'sortHandler'
    },
    constructor: function(option) {
      if (option) {
        _.extend(this, option);
      }
      if (this.events) {
        this.delegateEvents();
      }
      this.template = _func.getTemplate('hotelListSortTemplate');
      _n.on('clearSort', _.bind(this.clearSort, this));
    }
  });


  /*}}} */


  /*[HotelListHotelsModel] 酒店列表模型{{{ */

  HotelListHotelsModel = Backbone.Model.extend({
    defaults: {
      hotelListData: null,
      recommendHotelListData: null,
      memberLevel: ''
    },
    fetchHotelList: function(type) {
      var _call, url;
      _n.trigger('showLoading');
      if (type === 'filterChange') {
        _n.trigger('clearSort');

        /*重置分页 */
        _n.trigger('clearPage');
      }
      if (type === 'sortChange') {
        _n.trigger('clearPage');
      }
      if (type === 'recommend') {
        url = _func.getRecommanHotelListdUrl();
      } else {
        url = _func.getUrlBySearch();
      }
      _call = function(xhr, status) {
        var $hotelList, data;
        _n.trigger('hideLoading');
        if (_func.checkSuccessStatus(xhr.status)) {
          if (xhr.responseJSON) {
            data = xhr.responseJSON;
          } else if (xhr.responseText) {
            data = $.parseJSON(xhr.responseText);
          }
          if (!data || data.ErrorCode) {
            this.set('hotelListData', []);
            _n.trigger('refreshPage', 0);
            _n.trigger('showError', '华掌柜忙不过来了，请刷新页面试试!');
            return;
          }
          if (type === 'recommend') {
            this.set('recommendHotelListData', data);
          } else {
            this.set('hotelListData', data);

            /*如果数据为空，则置空分页 */
            if (data) {
              _n.trigger('refreshPage', data.TotalCount);
            } else {
              _n.trigger('refreshPage', 0);
            }
            if (type === 'pageChange') {
              $hotelList = $('#Plist_hotel');
              $('body').animate({
                'scrollTop': $hotelList.offset().top - 52
              });
            }
          }
        } else if (status === 'error' && type !== 'recomment') {
          this.set('hotelListData', []);
          _n.trigger('refreshPage', 0);
          _n.trigger('showError', '华掌柜忙不过来了，请刷新页面试试!');
        }
      };
      return _func.getAjaxData(url, _.bind(_call, this));
    },
    fetchRoomType: function($hotel) {
      var ActivityID, CheckInDate, CheckOutDate, HallIds, HotelID, MemberLeveList, QueryRoomType, urlParam;
      HotelID = $hotel.data('hotelId');
      HallIds = $hotel.data('hallIds');
      QueryRoomType = $hotel.data('queryRoomType');
      CheckInDate = HZWeb.search.getParam('CheckInDate');
      CheckOutDate = HZWeb.search.getParam('CheckOutDate');
      ActivityID = HZWeb.search.getParam('ActivityID');
      MemberLeveList = _func.getQueryHotelListMemberLevel();
      urlParam = {
        HotelID: HotelID,
        HallIds: HallIds,
        CheckInDate: CheckInDate,
        CheckOutDate: CheckOutDate,
        QueryRoomType: QueryRoomType,
        ActivityID: ActivityID,
        MemberLeveList: MemberLeveList
      };
      if (HotelID && CheckInDate && CheckOutDate) {
        return _func.getAjaxData(_vars.getHotelRoomTypeUrl, function(xhr, status) {
          var data;
          if (_func.checkSuccessStatus(xhr.status)) {
            if (xhr.responseJSON) {
              data = xhr.responseJSON;
            } else if (xhr.responseText) {
              data = $.parseJSON(xhr.responseText);
            }
          }
          if (!data) {
            data = {};
          }
          _n.trigger('renderRoomType', HotelID, data);
        }, {
          data: urlParam
        });
      }
    },
    isEmptyHotelListData: function(data) {
      if (!data || !data.HotelList || !data.HotelList.length) {
        return true;
      }
    },
    setInitHotelList: function(data) {
      this.set('hotelListData', data);
      if (data && data.TotalCount) {
        _n.trigger('refreshPage', data.TotalCount);
      }
    },
    constructor: function() {
      Backbone.Model.apply(this, arguments);
      _n.on('fetchHotelList', _.bind(this.fetchHotelList, this));
      this.set('memberLevel', HZWeb.user.getMemberLevel());
      _n.on('USER_SIGNIN', (function(_this) {
        return function() {
          var memberLevel;
          memberLevel = HZWeb.user.getMemberLevel();
          return _this.set('memberLevel', memberLevel);
        };
      })(this));
    }
  });


  /*}}} */


  /*[HotelListHotelsListBase] 酒店列表基础View{{{ */

  HotelListHotelsListBase = Backbone.View.extend({
    updateRoomTypeMemberLevel: function() {
      var memberLevel;
      memberLevel = HZWeb.user.getMemberLevel();
      return this.$(".pricepopup .item[data-member-level=" + memberLevel + "]").each(function(index, item) {
        var $item;
        $item = $(item);
        if (!$item.hasClass('active')) {
          $item.siblings('.active').removeClass('active');
          $item.addClass('active');
        }
      });
    },
    renderRoomType: function(hotelId, data) {
      var $hotel, IsSignin, MemberLevel, MemberType, html;
      $hotel = this.$(".hotel[data-hotel-id=" + hotelId + "]");
      if ($hotel.length) {
        MemberLevel = HZWeb.user.getMemberLevel();
        MemberType = HZWeb.user.getMemberType();
        IsSignin = HZWeb.user.hasSigned();
        data = _.extend(data, {
          MemberLevel: MemberLevel,
          MemberType: MemberType,
          IsSignin: IsSignin
        });
        html = _func.renderTemplate(__hotelListRoomType, data);
        $hotel.find('.roomtype').remove();
        return $(html).appendTo($hotel);
      }
    },
    getFavorCount: function(hotelId) {
      var $hotels, HotelIDList, call, hotel, i, len, urlParam;
      $hotels = this.$('.hotel');
      if (!hotelId) {
        HotelIDList = [];
        for (i = 0, len = $hotels.length; i < len; i++) {
          hotel = $hotels[i];
          HotelIDList.push(hotel.getAttribute('data-hotel-id'));
        }
      } else {
        HotelIDList = [].concat(hotelId);
      }
      if (HotelIDList.length) {
        HotelIDList = HotelIDList.join(',');
        urlParam = {
          HotelIDList: HotelIDList
        };
        call = function(xhr, status) {
          var data;
          if (_func.checkSuccessStatus(xhr.status)) {
            if (xhr.responseJSON) {
              data = xhr.responseJSON;
            } else if (xhr.responseText) {
              data = $.parseJSON(xhr.responseText);
            }
            this.renderFavorCount(data);
          }
        };
        _func.getAjaxData(_vars.getFavorAmountUrl, _.bind(call, this), {
          data: urlParam
        });
      }
    },
    getHotelInfo: function(type, hotelId) {
      var $hotels, HotelIDList, _url, call, hotel, i, len, urlParam;
      $hotels = this.$('.hotel');
      if (!hotelId) {
        HotelIDList = [];
        for (i = 0, len = $hotels.length; i < len; i++) {
          hotel = $hotels[i];
          if (type === 'book' && hotel.getAttribute('data-open-rev') !== 'true') {
            continue;
          } else {
            HotelIDList.push(hotel.getAttribute('data-hotel-id'));
          }
        }
      } else {
        HotelIDList = [].concat(hotelId);
      }
      if (HotelIDList.length) {
        HotelIDList = HotelIDList.join(',');
        urlParam = {
          HotelIDList: HotelIDList
        };
        call = function(xhr, status) {
          var data;
          if (_func.checkSuccessStatus(xhr.status)) {
            if (xhr.responseJSON) {
              data = xhr.responseJSON;
            } else if (xhr.responseText) {
              data = $.parseJSON(xhr.responseText);
            }
            if (type === 'favor') {
              this.renderFavorCount(data);
            } else if (type === 'book') {
              this.renderLastReservation(data);
            } else if (type === 'commentseg') {
              this.renderMaxCommentsSeg(data);
            }
          }
        };
        if (type === 'favor') {
          _url = _vars.getFavorAmountUrl;
        } else if (type === 'book') {
          _url = _vars.getLastReservationUrl;
        } else if (type === 'commentseg') {
          _url = _vars.getMaxCommentsSegUrl;
        }
        _func.getAjaxData(_url, _.bind(call, this), {
          data: urlParam
        });
      }
    },
    render: function() {
      var checkInDate, checkOutDate, hotelListData;
      hotelListData = this.model.get('hotelListData');
      if (hotelListData) {
        checkInDate = HZWeb.search.getParam('CheckInDate');
        checkOutDate = HZWeb.search.getParam('CheckOutDate');
        _.extend(hotelListData, {
          DetailPagePrefix: _vars.detailPagePrefix,
          DetailPageOverseaPrefix: _vars.detailPageOverseaPrefix,
          CheckInDate: checkInDate,
          CheckOutDate: checkOutDate,
          DefaultHotelPhoto: _vars.defaultHotelPhoto
        });
      } else {
        hotelListData = [];
      }
      _n.trigger('hotelTotalCountChange', hotelListData.TotalCount || 0);
      return this.$el.html(this.template(hotelListData));
    },
    updateHotelLowestPrice: function(hotelId, data) {
      var $hotel, $pricearea, newHotelLowestPrice, oldHotelLowestPrice;
      newHotelLowestPrice = data.MinMarketPrice;
      $hotel = this.$(".hotel[data-hotel-id=" + hotelId + "]");
      if (newHotelLowestPrice && $hotel.length) {
        $pricearea = $hotel.find('.rarea .pricearea');
        oldHotelLowestPrice = parseFloat($pricearea.data('hotelLowestPrice'));
        if (newHotelLowestPrice !== oldHotelLowestPrice) {
          return $pricearea.html("<span class='oldprice Lpr5'><i>￥</i>" + (TplHelper.calculationPrice("p18", 1, oldHotelLowestPrice)) + "</span><span class='price'><i>￥</i>" + (TplHelper.calculationPrice("p29", 0, newHotelLowestPrice)) + "<i>起</i></span>");
        }
      }
    },
    renderRecommandHotelList: function() {
      var checkInDate, checkOutDate, hotelListHtml, recommendHotelListData, recommendHotelListHtml;
      recommendHotelListData = this.model.get('recommendHotelListData');
      if (recommendHotelListData && !this.model.isEmptyHotelListData(recommendHotelListData)) {
        checkInDate = HZWeb.search.getParam('CheckInDate');
        checkOutDate = HZWeb.search.getParam('CheckOutDate');
        _.extend(recommendHotelListData, {
          DetailPagePrefix: _vars.detailPagePrefix,
          CheckInDate: checkInDate,
          CheckOutDate: checkOutDate,
          DefaultHotelPhoto: _vars.defaultHotelPhoto
        });
        hotelListHtml = this.template(recommendHotelListData);
        recommendHotelListHtml = _func.renderTemplate('recommendHotelListTemplate', {
          html: hotelListHtml
        });
        this.$el.html(recommendHotelListHtml);
        this.showHotelMap();
        this.getHotelInfo('favor');
      }
    },
    initRecommandHotelList: function() {
      var $hotels;
      $hotels = $('.hotellist_box .hotel');
      if (!$hotels.length && this.model.isEmptyHotelListData(_vars.hotelListData)) {
        this.model.fetchHotelList('recommend');
      }
    },
    hideRecommandHotelList: function() {
      this.$('.hotellist').hide();
    },
    showHotelMap: function(e) {
      var $hotel, hotelId, hotelName, hotelStyle, lat, lng;
      if (!e) {
        $hotel = this.$('.hotel:eq(0)');
      } else {
        $hotel = $(e.currentTarget);
      }
      if ($hotel.length) {
        hotelId = $hotel.data('hotelId');
        hotelStyle = $hotel.data('hotelStyle');
        hotelName = $hotel.find('.hotelname h3 a').text();
        lat = $hotel.data('lat');
        lng = $hotel.data('lng');
        _n.trigger('DELAY:hotelListMapChange', hotelId, hotelName, hotelStyle, lat, lng);
      }
    },
    getListOrderData: function($btn) {
      var $hotel, $room, ActivityID, BookingType, CheckInDate, CheckOutDate, HallIDs, HotelID, IsRent, RoomType;
      $room = $btn.parents('.room');
      $hotel = $btn.parents('.hotel');
      HotelID = $hotel.data('hotelId');
      HallIDs = $hotel.data('hallIds');
      CheckInDate = HZWeb.search.getParam('CheckInDate');
      CheckOutDate = HZWeb.search.getParam('CheckOutDate');
      RoomType = $btn.data('roomType');
      ActivityID = $btn.data('activityId');
      IsRent = $btn.data('rent');
      if (IsRent) {

        /*时租房 */
        BookingType = 'RentBooking';
      } else if (ActivityID) {

        /*活动 */
        BookingType = 'Activity';
      } else {

        /*未设置 */
        BookingType = 'NoSet';
      }
      return {
        HotelID: HotelID,
        HallIDs: HallIDs,
        CheckInDate: CheckInDate,
        CheckOutDate: CheckOutDate,
        ActivityID: ActivityID,
        RoomType: RoomType,
        BookingType: BookingType
      };
    },
    orderHandler: function(e) {
      var $self, postData;
      $self = $(e.currentTarget);
      if ($self.hasClass('gray')) {
        return;
      }
      postData = this.getListOrderData($self);
      _func.createPostRequest(_vars.createOrderUrl, postData);
      return false;
    },
    showPriceHandler: function(e) {
      var $hotel, $popup, $self, ActivityID, CheckInDate, CheckOutDate, HotelID, MemberLevelList, RoomTypeID, memberType;
      $self = $(e.currentTarget);
      memberType = $self.data('memberType');
      if (memberType !== 'company') {

        /*显示价格框 */
        $popup = $self.find('.pricepopup');
        $popup.show();

        /*展开箭头 */
        $self.find('.arrow').addClass('reverse');

        /*是否已加载 */
        if ($self.data('loadLock') !== 'lock') {
          $self.data('loadLock', 'lock');
          $hotel = $self.parents('.hotel');
          HotelID = $hotel.data('hotelId');
          CheckInDate = HZWeb.search.getParam('CheckInDate');
          CheckOutDate = HZWeb.search.getParam('CheckOutDate');
          RoomTypeID = $self.data('roomType');
          ActivityID = $self.data('activityId');
          MemberLevelList = _func.getQueryHotelListMemberLevel() || '';
          _func.getAjaxData(_vars.getDailyRoomPriceUrl, function(xhr, status) {
            var MemberLevel, data, html, template;
            if (_func.checkSuccessStatus(xhr.status)) {
              if (xhr.responseJSON) {
                data = xhr.responseJSON;
              } else {
                data = $.parseJSON(xhr.responseText);
              }
            } else {
              data = {};
            }
            MemberLevel = HZWeb.user.getMemberLevel();
            MemberLevelList = _vars.MemberLevel;
            _.extend(data, {
              MemberLevel: MemberLevel,
              MemberLevelList: MemberLevelList
            });
            template = _n.service('template').getTemplate('memberPricePopupTemplate');
            html = template(data);
            return $self.find('.popupcontentbox').html(html);
          }, {
            data: {
              CheckInDate: CheckInDate,
              CheckOutDate: CheckOutDate,
              HotelID: HotelID,
              RoomTypeID: RoomTypeID,
              ActivityID: ActivityID,
              MemberLevelList: MemberLevelList
            }
          });
        }
      }
      return false;
    },
    hidePriceHandler: function(e) {
      var $popup, $self;
      $self = $(e.currentTarget);
      $self.find('.arrow').removeClass('reverse');
      $popup = $self.find('.pricepopup');
      $popup.hide();
      return false;
    },
    backtosearchHandler: function(e) {
      var doc, scrollTop, time, top;
      doc = document;
      top = Math.max(doc.body.scrollTop, doc.documentElement.scrollTop);
      time = 400;
      time = parseInt(1000 / time) * time;
      scrollTop = 0;
      $('html, body').animate({
        scrollTop: scrollTop
      }, time);
    },
    favorAdd: function() {
      var HotelID, self;
      self = this;
      HotelID = _stor('favorAddHotelId');
      _func.getAjaxData(_vars.addFavorHotelUrl, (function(_this) {
        return function(xhr, status) {
          var $favor, $hotel;
          if (_func.checkSuccessStatus(xhr.status)) {
            $hotel = _this.$(".hotel[data-hotel-id=" + HotelID + "]");
            $favor = $hotel.find('.favor_count');
            $favor.data('save', 'saved');
            self.favorAddCallback($favor);
          }
        };
      })(this), {
        data: {
          HotelID: HotelID
        },
        type: 'PUT'
      });
    },
    favorDelete: function(HotelID) {
      var self;
      self = this;
      return _func.getAjaxData(_vars.deleteFavorHotelUrl, (function(_this) {
        return function(xhr, status) {
          var $favor, $hotel, favorCount;
          if (_func.checkSuccessStatus(xhr.status)) {
            $hotel = _this.$(".hotel[data-hotel-id=" + HotelID + "]");
            $favor = $hotel.find('.favor_count');
            $favor.data('save', '');
            favorCount = $favor.data('favorCount');
            self.favorDeleteCallback($favor, favorCount);
          }
        };
      })(this), {
        data: {
          HotelID: HotelID
        },
        type: 'DELETE'
      });
    },
    favorClickHandler: function(e) {
      var $hotel, $self, HotelID;
      $self = $(e.currentTarget);
      $hotel = $self.parents('.hotel');
      HotelID = $hotel.data('hotelId');
      if ($self.data('save') === 'saved') {
        if (HZWeb.user.hasSigned()) {
          this.favorDelete(HotelID);
        }
      } else {
        $hotel = $self.parents('.hotel');
        HotelID = $hotel.data('hotelId');
        _stor('favorAddHotelId', HotelID, _stor.REWRITE);
        if (!HZWeb.user.hasSigned()) {
          HZWeb.user.signInPopup(_.bind(this.favorAdd, this));
        } else {
          this.favorAdd();
        }
      }
      return false;
    },
    fullviewHandler: function(e) {
      var $fullview, $html, $self, html, url;
      $self = $(e.currentTarget);
      $fullview = $('.Mpopup.fullview');
      url = $self.data('href');
      if (!$fullview.length) {
        html = _func.renderTemplate('HotelCommonFullView', {
          url: url
        });
        $html = $(html);
        $html.appendTo('body');
        $html.on('click', function(e) {
          $(this).hide();
        }).find('.inner').on('click', function(e) {
          e.stopPropagation();
        }).find('.middle_close').on('click', function(e) {
          var $popup;
          $self = $(this);
          $popup = $self.parents('.Mpopup');
          return $popup.hide();
        });
        return $html.show();
      } else {
        $fullview.find('iframe').attr('src', url);
        return $fullview.show();
      }
    },
    signRefreshRoomType: function(hotelId, type) {
      var $hotel, scrollTop, time;
      this.shrinkAll();
      $hotel = this.$(".hotel[data-hotel-id=" + hotelId + "]");
      time = 400;
      scrollTop = $hotel.offset().top;
      scrollTop = scrollTop - 36 - 52;
      window.scrollTo(window.scrollX, scrollTop);
      $hotel.find('.viewroomtype').trigger('click');
    },
    signinHandler: function(e) {
      var $hotel, $self, hotelId;
      $self = $(e.currentTarget);
      $hotel = $self.parents('.hotel');
      hotelId = $hotel.data('hotelId');
      if (HZWeb.user.hasSigned()) {
        $self.hide();
      } else {
        HZWeb.user.signInPopup(_.bind(function() {
          $self.hide();
          return this.signRefreshRoomType(hotelId, 'cleanOther');
        }, this));
      }
    },
    enterHotelHandler: function(e) {
      var $self;
      $self = $(e.currentTarget);
      return $self.addClass('hover');
    },
    leaveHotelHandler: function(e) {
      var $self;
      $self = $(e.currentTarget);
      return $self.removeClass('hover');
    }
  });


  /*}}} */


  /*[HotelListHotelsList] 国内酒店列表View {{{ */

  HotelListHotelsList = HotelListHotelsListBase.extend({
    renderLastReservation: function(data) {
      _.each(data.ReverstionTimeList, function(item) {
        var $hotel, $reserv, date, displayDate;
        $hotel = $("#Plist_hotel .hotel[data-hotel-id='" + item.HotelID + "']");
        if ($hotel.length) {
          $reserv = $hotel.find('.lastorder');
          date = item.ReversationTime.match(/\d+/);
          if (date && date[0]) {
            date = parseInt(date[0]);
            displayDate = TplHelper.getDisplayDate2({
              CommentTime: date
            });
            if (displayDate) {
              return $reserv.html("<i class='Cicon small_clock'></i>最新的预订：" + displayDate);
            }
          }
        }
      });
    },
    renderMaxCommentsSeg: function(data) {
      if (data.CommentSegContent && data.CommentSegContent.length) {
        _.each(data.CommentSegContent, function(item) {
          var $hotel, $label;
          $hotel = $("#Plist_hotel .hotel[data-hotel-id='" + item.HotelID + "']");
          if ($hotel.length) {
            $label = $hotel.find('.commentseg');
            $label.html("<i class='Cicon small_msg'></i>大家说：<span>" + item.MapName + "</span>");
          }
        });
      }
    },
    render: function() {
      HotelListHotelsListBase.prototype.render.apply(this, arguments);
      this.showHotelMap();
      this.getHotelInfo('favor');
      this.getHotelInfo('book');
      return this.getHotelInfo('commentseg');
    },
    renderFavorCount: function(data) {
      var favorHotels;
      favorHotels = HZWeb.user.get('favorHotels');
      return _.each(data.FavoriteList, function(item) {
        var $favor, $hotel, hasSaved;
        $hotel = $("#Plist_hotel .hotel[data-hotel-id='" + item.HotelID + "']");
        hasSaved = false;
        if (favorHotels) {
          if (_.findWhere(favorHotels, {
            HotelID: item.HotelID
          })) {
            hasSaved = true;
          }
        }
        if ($hotel.length) {
          $favor = $hotel.find('.favor_count');
          $favor.data('favorCount', item.FavoriteAmount);
          if (!hasSaved) {
            return $favor.html("<i class='Cicon small_favor'></i><span>收藏</span><span class='num'>" + item.FavoriteAmount + "</span>");
          } else {
            $favor.html("<i class='Cicon small_favor saved'></i><span>已收藏</span>");
            return $favor.data('save', 'saved');
          }
        }
      });
    },
    renderLoadRoomType: function(hotelId) {
      var $hotel, IsSignin, MemberLevel, MemberType, html, loadImg;
      $hotel = this.$(".hotel[data-hotel-id=" + hotelId + "]");
      MemberLevel = HZWeb.user.getMemberLevel();
      MemberType = HZWeb.user.getMemberType();
      IsSignin = HZWeb.user.hasSigned();
      loadImg = _vars.loadImg80x34;
      html = _func.renderTemplate(__hotelListRoomType, {
        MemberLevel: MemberLevel,
        MemberType: MemberType,
        IsSignin: IsSignin,
        loadImg: loadImg
      });
      return $(html).appendTo($hotel);
    },
    renderRecommandHotelList: function() {
      HotelListHotelsListBase.prototype.renderRecommandHotelList.apply(this, arguments);
      this.getHotelInfo('book');
      return this.getHotelInfo('commentseg');
    },
    expandHandler: function(e) {
      var $hotel, $roomtype, $self;
      $self = $(e.currentTarget);
      $hotel = $self.parents('.hotel');
      $roomtype = $hotel.find('.roomtype');
      if ($self.data('init') === 'inited') {
        if ($roomtype.length) {
          if ($roomtype.is(':visible')) {
            $roomtype.hide();
            $self.find('span').text('展开全部房型');
            $self.find('.arrow').removeClass('reverse');
          } else {
            $roomtype.show();
            $self.find('span').text('收起全部房型');
            $self.find('.arrow').addClass('reverse');
          }
        }
      } else {
        $self.data('init', 'inited');
        $self.find('span').text('收起全部房型');
        $self.find('.arrow').addClass('reverse');
        this.renderLoadRoomType($hotel.data('hotelId'));
        this.model.fetchRoomType($hotel);
      }
      return false;
    },
    shrinkAll: function(e) {
      var $roomtype;
      $roomtype = this.$('.roomtype');
      _.each($roomtype, function(item, index) {
        var $hotel, $viewlink;
        $hotel = $(item).parents('.hotel');
        $(item).remove();
        $viewlink = $hotel.find('.viewroomtype');
        $viewlink.data('init', '').find('span').text('展开全部房型');
        $viewlink.find('.arrow').removeClass('reverse');
      });
    },
    favorEnterHandler: function(e) {
      var $self;
      $self = $(e.currentTarget);
      $self.addClass('active').find('.Cicon').addClass('active');
      return false;
    },
    favorLeaveHandler: function(e) {
      var $self;
      $self = $(e.currentTarget);
      $self.removeClass('active').find('.Cicon').removeClass('active');
      return false;
    },

    /*[favorCallback] 添加收藏成功的回调函数{{{ */
    favorAddCallback: function(favorElement) {
      return favorElement.html("<i class='Cicon small_favor saved'></i><span>已收藏</span>");
    },

    /*}}} */
    favorDeleteCallback: function(favorElement, favorCount) {
      return favorElement.html("<i class='Cicon small_favor'></i><span>收藏</span><span class='num'>" + favorCount + "</span>");
    },
    enterHotelHandler: function(e) {
      HotelListHotelsListBase.prototype.enterHotelHandler.apply(this, arguments);
      return this.showHotelMap(e);
    },
    events: {
      'click .viewroomtype': 'expandHandler',
      'click .orderbtn': 'orderHandler',
      'mouseenter .roomtype .pricearea': 'showPriceHandler',
      'mouseleave .roomtype .pricearea': 'hidePriceHandler',
      'mouseenter .favor_count': 'favorEnterHandler',
      'mouseleave .favor_count': 'favorLeaveHandler',
      'click .favor_count': 'favorClickHandler',
      'click .fullview': 'fullviewHandler',
      'mouseenter .hotel': 'enterHotelHandler',
      'mouseleave .hotel': 'leaveHotelHandler',
      'click .backtosearch a': 'backtosearchHandler',
      'click .signinlink': 'signinHandler'
    },
    constructor: function(option, type) {
      Backbone.View.apply(this, arguments);
      this.template = _func.getTemplate('HotelListHotelBox');
      if (type === 'recommend') {
        this.listenTo(this.model, 'change:recommendHotelListData', this.renderRecommandHotelList);
        this.initRecommandHotelList();
      } else {
        this.showHotelMap();
        this.getHotelInfo('favor');
        this.getHotelInfo('book');
        this.getHotelInfo('commentseg');
        this.listenTo(this.model, 'change:hotelListData', this.render);
      }
      _n.on('renderRoomType', _.bind(this.renderRoomType, this));
      _n.on('renderRoomType', _.bind(this.updateHotelLowestPrice, this));
      _n.on('changeFavorHotels', _.bind(this.getFavorCount, this));

      /*会员登录后自动更新当前高亮会员价 */
    }
  });


  /*}}} */


  /*[HotelListHotelsListOversea] 国际版酒店列表View {{{ */

  HotelListHotelsListOversea = HotelListHotelsListBase.extend({
    render: function() {
      var checkInDate, checkOutDate, hotelListData;
      hotelListData = this.model.get('hotelListData');
      if (hotelListData) {
        checkInDate = HZWeb.search.getParam('CheckInDate');
        checkOutDate = HZWeb.search.getParam('CheckOutDate');
        _.extend(hotelListData, {
          DetailPagePrefix: _vars.detailPagePrefix,
          DetailPageOverseaPrefix: _vars.detailPageOverseaPrefix,
          CheckInDate: checkInDate,
          CheckOutDate: checkOutDate,
          DefaultHotelPhoto: _vars.defaultHotelPhoto,
          RoomCount: _vars.requestParams.RoomCount,
          CheckInCountPerRoom: _vars.requestParams.CheckInCountPerRoom
        });
      } else {
        hotelListData = [];
      }
      _n.trigger('hotelTotalCountChange', hotelListData.TotalCount || 0);
      this.$el.html(this.template(hotelListData));
      this.showHotelMap();
      return this.getHotelInfo('favor');
    },
    renderFavorCount: function(data) {
      var favorHotels;
      favorHotels = HZWeb.user.get('favorHotels');
      return _.each(data.FavoriteList, function(item) {
        var $favor, $hotel, hasSaved;
        $hotel = $("#Plist_hotel .hotel[data-hotel-id='" + item.HotelID + "']");
        hasSaved = false;
        if (favorHotels) {
          if (_.findWhere(favorHotels, {
            HotelID: item.HotelID
          })) {
            hasSaved = true;
          }
        }
        if ($hotel.length) {
          $favor = $hotel.find('.favor_count');
          if (hasSaved) {
            $favor.html("<a href='javascript:;' class='Cicon big_favor big_favor_red'></a>");
            return $favor.data('save', 'saved');
          } else {
            return $favor.html("<a href='javascript:;' class='Cicon big_favor_o'><i class='character'></i><i class='add'></i></a>");
          }
        }
      });
    },
    favorAddCallback: function(favorElement) {
      return favorElement.html("<i class='Cicon big_favor big_favor_red'></i>");
    },
    favorDeleteCallback: function(favorElement) {
      return favorElement.html('<span class="favor_count"><a href="javascript:;" class="Cicon big_favor_o"><i class="character"></i><i class="add"></i></a></span>');
    },
    enterHotelHandler: function(e) {
      HotelListHotelsListBase.prototype.enterHotelHandler.apply(this, arguments);
      return this.showHotelMap(e);
    },
    enterHotelDescHandler: function(e) {
      var $descbox;
      $descbox = $(e.currentTarget).parent();
      return $descbox.stop(true).animate({
        top: 0
      });
    },
    leaveHotelDescHandler: function(e) {
      var $descbox;
      $descbox = $(e.currentTarget).parent();
      return $descbox.stop(true).animate({
        top: 122
      });
    },
    events: {
      'click .favor_count': 'favorClickHandler',
      'mouseenter .hotel': 'enterHotelHandler',
      'mouseleave .hotel': 'leaveHotelHandler',
      'click .backtosearch a': 'backtosearchHandler',
      'click .signinlink': 'signinHandler',
      'mouseenter .hotel .desc': 'enterHotelDescHandler',
      'mouseleave .hotel .desc': 'leaveHotelDescHandler'
    },
    constructor: function(option, type) {
      Backbone.View.apply(this, arguments);
      this.template = _func.getTemplate('HotelListHotelBoxOversea');
      if (type === 'recommend') {
        this.listenTo(this.model, 'change:recommendHotelListData', this.renderRecommandHotelList);
        this.initRecommandHotelList();
      } else {
        this.showHotelMap();
        this.getHotelInfo('favor');
        this.listenTo(this.model, 'change:hotelListData', this.render);
      }
      _n.on('changeFavorHotels', _.bind(this.getFavorCount, this));
    }
  });


  /*}}} */


  /*[HotelListHotelsListSale] 大促销酒店列表View{{{ */

  HotelListHotelsListSale = HotelListHotelsListBase.extend({
    render: function() {
      var self;
      self = this;
      HotelListHotelsListBase.prototype.render.apply(self, arguments);
      setTimeout(function() {
        var $hotels;
        $hotels = $('.hotellist_box .hotel');
        if ($hotels.length) {
          return $.each($hotels, function(index, hotel) {
            var $$hotel;
            $$hotel = $(hotel);
            self.renderLoadRoomType($$hotel.data('hotelId'));
            return self.model.fetchRoomType($$hotel);
          });
        }
      }, 0);
    },
    constructor: function(option, type) {
      Backbone.View.apply(this, arguments);
      this.template = _func.getTemplate('HotelListHotelBoxSale');
      this.listenTo(this.model, 'change:hotelListData', this.render);
      this.initSaleHotelList();
      _n.on('renderRoomType', _.bind(this.renderRoomType, this));
    },
    initSaleHotelList: function() {
      var $hotels, _self;
      $hotels = $('.hotellist_box .hotel');
      _self = this;
      if (!$hotels.length && this.model.isEmptyHotelListData(_vars.hotelListData)) {
        if (!_n.event.eventHandle._events.saleInitHotelList) {
          _n.on('saleInitHotelList', function() {
            if (_vars.currentActivityFirstCity && _vars.currentAcitivityLimitDate) {
              _self.model.fetchHotelList('sale');
              _vars.currentAcitivityLimitDate = void 0;
              _vars.currentActivityFirstCity = void 0;
            }
          });
        }
      }
    },
    events: {
      'click .orderbtn': 'orderHandler',
      'mouseenter .roomtype .pricearea': 'showPriceHandler',
      'mouseleave .roomtype .pricearea': 'hidePriceHandler',
      'click .fullview': 'fullviewHandler',
      'click .backtosearch a': 'backtosearchHandler',
      'click .signinlink': 'signinHandler',
      'click .viewroomtype': 'expandHandler'
    },
    renderLoadRoomType: function(hotelId) {
      var $hotel, $roomtype, IsSignin, MemberLevel, MemberType, html, loadImg;
      $hotel = this.$(".hotel[data-hotel-id=" + hotelId + "]");
      MemberLevel = HZWeb.user.getMemberLevel();
      MemberType = HZWeb.user.getMemberType();
      IsSignin = HZWeb.user.hasSigned();
      loadImg = _vars.loadImg80x34;
      html = _func.renderTemplate(__hotelListRoomType, {
        MemberLevel: MemberLevel,
        MemberType: MemberType,
        IsSignin: IsSignin,
        loadImg: loadImg
      });
      $roomtype = $hotel.find('.roomtype');
      if ($roomtype.length) {
        return $roomtype.replaceWith(html);
      } else {
        return $(html).appendTo($hotel);
      }
    },
    expandHandler: function(e) {
      var $roomtype, $self;
      $self = $(e.currentTarget);
      $roomtype = $self.parents('.roomtype').find('tr.room');
      if ($roomtype.eq(2).hasClass('Ldn')) {
        $roomtype.filter(':gt(1)').removeClass('Ldn');
        $self.find('span').text('收起全部房型');
        return $self.find('.arrow').addClass('reverse');
      } else {
        $roomtype.filter(':gt(1)').addClass('Ldn');
        $self.find('span').text('更多房型');
        return $self.find('.arrow').removeClass('reverse');
      }
    },
    signRefreshRoomType: function(hotelId, type) {
      var $hotel, scrollTop, time;
      $hotel = this.$(".hotel[data-hotel-id=" + hotelId + "]");
      time = 400;
      scrollTop = $hotel.offset().top;
      scrollTop = scrollTop - 36 - 52;
      window.scrollTo(window.scrollX, scrollTop);
      this.model.fetchHotelList('sale');
    }
  });


  /*}}} */

  if (_stor('HOTELTYPE') === 'oversea') {
    __hotelListHotelsDependTemplates = ['HotelListHotelBoxOverseaTemplate'];
    __hotelListHotelsList = HotelListHotelsListOversea;
  } else if (_stor('HOTELTYPE') === 'sale') {
    __hotelListHotelsDependTemplates = ['HotelListHotelBoxSaleTemplate', 'HotelListRoomTypeSaleTemplate'];
    __hotelListHotelsList = HotelListHotelsListSale;
    __hotelListRoomType = 'HotelListRoomTypeSale';
  } else {
    __hotelListHotelsDependTemplates = ['HotelListHotelBoxTemplate', 'HotelListRoomTypeTemplate'];
    __hotelListRoomType = 'HotelListRoomType';
    __hotelListHotelsList = HotelListHotelsList;
  }


  /*[HotelListHotels] 酒店列表{{{ */

  HotelListHotels = Backbone.View.extend({
    constructor: function(option) {
      Backbone.View.apply(this, arguments);
      if (_stor('HOTELTYPE') === 'sale') {
        this.hotelListRecommandHotelList = new HotelListHotelsListSale({
          el: this.$('.hotellist_box'),
          $el: this.$('.hotellist_box'),
          model: this.model
        }, 'sale');
      } else {
        this.hotelListHotelsSort = new HotelListHotelsSort({
          el: this.$('.sortbox'),
          $el: this.$('.sortbox'),
          model: this.model
        });
        this.hotelListHotelsList = new __hotelListHotelsList({
          el: this.$('.hotellist_box'),
          $el: this.$('.hotellist_box'),
          model: this.model
        });
        this.hotelListRecommandHotelList = new __hotelListHotelsList({
          el: this.$('.recommend_hotellist_box'),
          $el: this.$('.recommend_hotellist_box'),
          model: this.model
        }, 'recommend');
      }
      this.hotelListHotelsPage = new HotelListHotelsPage({
        el: this.$('.Cpage'),
        $el: this.$('.Cpage'),
        model: this.model
      });
      if (option.params.initHotelList) {
        this.model.setInitHotelList(_vars.hotelListData);
      }
    }
  });

  _n.block('block.hotelListHotels', {
    depend: __hotelListHotelsDependTemplates,
    instance: {},
    reset: function(elem) {
      var block, blockInstanceId;
      blockInstanceId = $(elem).data('blockInstanceId');
      block = this.instance[blockInstanceId];
      block.model.set(block.model.defaults, {
        silent: true
      });
      block.hotelListRecommandHotelList.initSaleHotelList();
    },
    init: function(elem, params) {
      var block, blockInstanceId;
      if (params) {
        params = _func.formatUrlParam(params);
      } else {
        params = {};
      }
      block = new HotelListHotels({
        el: elem,
        $el: $(elem),
        params: params,
        model: new HotelListHotelsModel()
      });
      blockInstanceId = "blockInstance" + (+new Date()) + (parseInt(Math.random() * 100000));
      this.instance[blockInstanceId] = block;
      return $(elem).data('blockInstanceId', blockInstanceId);
    },
    destroy: function(elem) {
      var block, blockInstanceId;
      blockInstanceId = $(elem).data('blockInstanceId');
      block = this.instance[blockInstanceId];
      block.destroy();
      $(elem).data('blockInstanceId', null);
    }
  });


  /*}}} */


  /*[block.hotelDetailRoomBase] 酒店详情页房型数据基础模型{{{ */

  HotelDetailRoomBaseModel = Backbone.Model.extend({
    defaults: {
      roomTypeData: null,
      memberLevel: ''
    },
    set: function(attributes, options) {
      Backbone.Model.prototype.set.apply(this, arguments);
      if ((_.isObject(attributes) && _.has(attributes, 'roomTypeData')) || attributes === 'roomTypeData') {
        return this.trigger('changeRoomTypeData');
      }
    },
    getFetchRoomTypeParam: function() {
      var ActivityID, CheckInDate, CheckOutDate, HallIds, HotelID, MemberLeveList, QueryRoomType, search;
      HotelID = _vars.requestParams.HotelId;
      HallIds = _vars.requestParams.HallIds;
      ActivityID = _vars.requestParams.ActivityID;
      QueryRoomType = _vars.requestParams.QueryRoomType;
      CheckInDate = $('#Pdetail_part2 .checkindate').val();
      CheckOutDate = $('#Pdetail_part2 .checkoutdate').val();
      MemberLeveList = _func.getQueryHotelListMemberLevel();

      /*更新search参数 */
      search = _n.service('search');
      search.setParam('CheckInDate', CheckInDate);
      search.setParam('CheckOutDate', CheckOutDate);
      return {
        HotelID: HotelID,
        HallIds: HallIds,
        ActivityID: ActivityID,
        QueryRoomType: QueryRoomType,
        CheckInDate: CheckInDate,
        CheckOutDate: CheckOutDate,
        MemberLeveList: MemberLeveList
      };
    },
    constructor: function(option) {
      Backbone.Model.apply(this, arguments);
      _n.on('refreshDetailRoomType', _.bind(this.fetchRoomType, this));
      this.set('memberLevel', HZWeb.user.getMemberLevel());
      _n.on('USER_SIGNIN', (function(_this) {
        return function() {
          return _this.set('memberLevel', HZWeb.user.getMemberLevel());
        };
      })(this));
    }
  });


  /*}}} */


  /*[HotelDetailRoomOverseaModel] 国际酒店详情页房型模型 {{{ */

  HotelDetailRoomOverseaModel = HotelDetailRoomBaseModel.extend({
    getFetchRoomTypeParam: function() {
      var urlParam;
      urlParam = HotelDetailRoomBaseModel.prototype.getFetchRoomTypeParam();
      urlParam.RoomCount = _vars.requestParams.RoomCount;
      urlParam.GuestPerRoom = _vars.requestParams.GuestPerRoom;
      return urlParam;
    },
    fetchRoomType: function() {
      var call, urlParam;
      urlParam = this.getFetchRoomTypeParam();
      call = function(xhr, status) {
        var data;
        if (_func.checkSuccessStatus(xhr.status)) {
          if (xhr.responseJSON) {
            data = xhr.responseJSON;
          } else if (xhr.responseText) {
            data = $.parseJSON(xhr.responseText);
          }
          return this.set('roomTypeData', {
            Rooms: data
          });
        } else if (status === 'error') {
          return this.set('roomTypeData', {});
        }
      };
      return _func.getAjaxData(_vars.getHotelRoomTypeUrl, _.bind(call, this), {
        data: urlParam
      });
    }
  });


  /*}}} */


  /*[HotelDetailRoomModel] 国内酒店详情页房型模型{{{ */

  HotelDetailRoomModel = HotelDetailRoomBaseModel.extend({
    fetchRoomType: function() {
      var call, urlParam;
      urlParam = this.getFetchRoomTypeParam();
      call = function(xhr, status) {
        var data;
        if (_func.checkSuccessStatus(xhr.status)) {
          if (xhr.responseJSON) {
            data = xhr.responseJSON;
          } else if (xhr.responseText) {
            data = $.parseJSON(xhr.responseText);
          }
          return this.set('roomTypeData', data);
        } else if (status === 'error') {
          return this.set('roomTypeData', {});
        }
      };
      return _func.getAjaxData(_vars.getHotelRoomTypeUrl, _.bind(call, this), {
        data: urlParam
      });
    }
  });


  /*}}} */


  /*[HotelDetailRoomBase] 酒店详情页基础View {{{ */

  HotelDetailRoomBase = Backbone.View.extend({
    render: function() {
      var DefaultPhoto, DefaultPhoto140x109, IsSignin, MemberLevel, MemberType, html, roomTypeData;
      roomTypeData = this.model.get('roomTypeData');
      MemberLevel = HZWeb.user.getMemberLevel();
      MemberType = HZWeb.user.getMemberType();
      IsSignin = HZWeb.user.hasSigned();
      DefaultPhoto = _vars.defaultPhoto54x54;
      DefaultPhoto140x109 = _vars.defaultPhoto140x109;
      roomTypeData = _.extend(roomTypeData, {
        MemberLevel: MemberLevel,
        MemberType: MemberType,
        IsSignin: IsSignin,
        DefaultPhoto140x109: DefaultPhoto140x109,
        DefaultPhoto: DefaultPhoto
      });
      html = this.template(roomTypeData);
      this.$('.roomtypebox').html(html);
      return _n.trigger('STATUS:detailRoomRenderFinish');
    },
    renderLoadImg: function() {
      var IsSignin, MemberLevel, MemberType, html, loadImg, roomTypeData;
      MemberLevel = HZWeb.user.getMemberLevel();
      MemberType = HZWeb.user.getMemberType();
      IsSignin = HZWeb.user.hasSigned();
      loadImg = _vars.loadImg80x34;
      roomTypeData = {
        MemberLevel: MemberLevel,
        MemberType: MemberType,
        IsSignin: IsSignin,
        loadImg: loadImg
      };
      html = this.template(roomTypeData);
      return this.$('.roomtypebox').html(html);
    },
    orderHandler: function(e) {
      var $self, postData;
      $self = $(e.currentTarget);
      if ($self.hasClass('gray')) {
        return;
      }
      postData = this.getDetailOrderData($self);
      _func.createPostRequest(_vars.createOrderUrl, postData);
      return false;
    },
    moreInfoHandler: function(e) {
      var $next, $nextBoundingClientRect, $nextHeight, $room, $self, $window, gap, windowHeight;
      $self = $(e.currentTarget);
      $room = $self.parents('.room');
      $next = $room.next();
      while ($next.length && !$next.hasClass('roominfo')) {
        $next = $next.next();
      }
      if ($next.is(':visible')) {
        $self.html('查看详情 <i class="arrow"></i>');
        $next.hide();
        $next.find('.roominfobox').removeClass('animation');
      } else {
        $self.html('收起详情 <i class="arrow reverse"></i>');
        $next.show();
        $window = $(window);
        windowHeight = $window.height();
        $nextBoundingClientRect = $next[0].getBoundingClientRect();
        $nextHeight = $nextBoundingClientRect.height || $next.height();
        gap = $nextHeight + $nextBoundingClientRect.top - windowHeight + 10;
        if (gap > 0) {
          $next.find('.roominfobox').addClass('animation');
          $window.scrollTop(($(document.body).scrollTop() || $(document.documentElement).scrollTop()) + gap);
        }
      }
    },
    closeMoreInfoHandler: function(e) {
      var $prev, $self;
      $self = $(e.currentTarget);
      $prev = $self.parents('.roominfo').prev();
      while ($prev.length && !$prev.hasClass('first')) {
        $prev = $prev.prev();
      }
      $prev.find('.more').html('查看详情 <i class="arrow"></i>');
      $self.parents('.roominfo').hide();
    },
    refreshRoomType: function(e) {
      this.renderLoadImg();
      return _n.trigger('refreshDetailRoomType');
    },
    updateCheckInDay: function(checkin) {
      return this.$('.checkindays').html("<span>共 " + checkin.checkInDays + " 晚</span>");
    },
    showFloatImage: function(e) {
      var $floatImage, $self;
      $self = $(e.currentTarget);
      $floatImage = $self.siblings('.floatimage');
      if ($floatImage.data('init') !== 'inited') {
        $floatImage.data('init', 'inited');
        $floatImage.html("<img src='" + ($self.attr('src')) + "' />");
      }
      $floatImage.addClass('show');
    },
    hideFloatImage: function(e) {
      var $floatImage, $self;
      $self = $(e.currentTarget);
      $floatImage = $self.siblings('.floatimage');
      $floatImage.removeClass('show');
    },
    constructor: function(option) {
      Backbone.View.apply(this, arguments);
      this.template = _func.getTemplate(__hotelDetailRoomTemplate);
      this.listenTo(this.model, 'changeRoomTypeData', this.render);
      this.listenTo(this.model, 'change:memberLevel', this.updateRoomTypeMemberLevel);
      _n.on('checkoutdateChoice', _.bind(this.updateCheckInDay, this));
      if (_vars.roomTypeData) {
        this.model.set('roomTypeData', {
          Rooms: _vars.roomTypeData
        });
      } else {
        this.model.set('roomTypeData', {});
      }
    }
  });


  /*}}} */


  /*[HotelDetailRoom] 国内酒店详情页房型View {{{ */

  HotelDetailRoom = HotelDetailRoomBase.extend({
    getDetailOrderData: function($btn) {
      var ActivityID, BookingType, CheckInDate, CheckOutDate, HallIDs, HotelID, IsRent, RoomType;
      HotelID = _vars.hotelId;
      HallIDs = '';
      CheckInDate = HZWeb.search.getParam('CheckInDate');
      CheckOutDate = HZWeb.search.getParam('CheckOutDate');
      RoomType = $btn.data('roomType');
      ActivityID = $btn.data('activityId');
      IsRent = $btn.data('rent');
      if (IsRent) {

        /*时租房 */
        BookingType = 'RentBooking';
      } else if (ActivityID) {

        /*活动 */
        BookingType = 'Activity';
      } else {

        /*未设置 */
        BookingType = 'NoSet';
      }
      return {
        HotelID: HotelID,
        HallIDs: HallIDs,
        CheckInDate: CheckInDate,
        CheckOutDate: CheckOutDate,
        ActivityID: ActivityID,
        RoomType: RoomType,
        BookingType: BookingType
      };
    },
    showPriceHandler: function(e) {
      var $popup, $self, ActivityID, CheckInDate, CheckOutDate, HotelID, MemberLevelList, RoomTypeID, memberType;
      $self = $(e.currentTarget);
      memberType = $self.data('memberType');
      if (memberType !== 'company') {

        /*显示价格框 */
        $popup = $self.find('.pricepopup');
        $popup.show();

        /*展开箭头 */
        $self.find('.arrow').addClass('reverse');

        /*是否已加载 */
        if ($self.data('loadLock') !== 'lock') {
          $self.data('loadLock', 'lock');
          HotelID = _vars.hotelId || '';
          CheckInDate = HZWeb.search.getParam('CheckInDate');
          CheckOutDate = HZWeb.search.getParam('CheckOutDate');
          RoomTypeID = $self.data('roomType');
          ActivityID = $self.data('activityId');
          MemberLevelList = _func.getQueryHotelListMemberLevel() || '';
          _func.getAjaxData(_vars.getDailyRoomPriceUrl, (function(_this) {
            return function(xhr, status) {
              var MemberLevel, data, html, template;
              if (_func.checkSuccessStatus(xhr.status)) {
                if (xhr.responseJSON) {
                  data = xhr.responseJSON;
                } else {
                  data = $.parseJSON(xhr.responseText);
                }
              } else {
                data = {};
              }
              MemberLevel = HZWeb.user.getMemberLevel();
              MemberLevelList = _vars.MemberLevel;
              _.extend(data, {
                MemberLevel: MemberLevel,
                MemberLevelList: MemberLevelList
              });
              template = _n.service('template').getTemplate('memberPricePopupTemplate');
              html = template(data);
              return $self.find('.popupcontentbox').html(html);
            };
          })(this), {
            data: {
              CheckInDate: CheckInDate,
              CheckOutDate: CheckOutDate,
              HotelID: HotelID,
              RoomTypeID: RoomTypeID,
              ActivityID: ActivityID,
              MemberLevelList: MemberLevelList
            }
          });
        }
      }
      return false;
    },
    hidePriceHandler: function(e) {
      var $popup, $self;
      $self = $(e.currentTarget);
      $self.find('.arrow').removeClass('reverse');
      $popup = $self.find('.pricepopup');
      $popup.hide();
      return false;
    },
    signinHandler: function(e) {
      var $self;
      $self = $(e.currentTarget);
      if (HZWeb.user.hasSigned()) {
        $self.hide();
      } else {
        HZWeb.user.signInPopup(_.bind(function() {
          $self.hide();
          return this.refreshRoomType();
        }, this));
      }
    },
    events: {
      'click .orderbtn': 'orderHandler',
      'click .more': 'moreInfoHandler',
      'click .close': 'closeMoreInfoHandler',
      'click .queryroomtype': 'refreshRoomType',
      'mouseenter .pricearea': 'showPriceHandler',
      'mouseleave .pricearea': 'hidePriceHandler',
      'click .signinlink': 'signinHandler',
      'mouseenter .roomname .img': 'showFloatImage',
      'mouseleave .roomname .img': 'hideFloatImage'
    }
  });


  /*}}} */


  /*[HotelDetailRoomOversea] 国际版详情页房型View {{{ */

  HotelDetailRoomOversea = HotelDetailRoomBase.extend({
    getDetailOrderData: function($btn) {
      var ActivityID, BookingType, CheckInDate, CheckOutDate, GuestPerRoom, HallIDs, HotelID, HotelLevel, RatePlanCode, RoomCount, RoomType, SegmentCategory;
      HotelID = _vars.hotelId;
      HallIDs = '';
      CheckInDate = HZWeb.search.getParam('CheckInDate');
      CheckOutDate = HZWeb.search.getParam('CheckOutDate');
      RoomType = $btn.data('roomType');
      ActivityID = $btn.data('activityId');
      BookingType = 0;
      RoomCount = _vars.requestParams.RoomCount;
      HotelLevel = _vars.HotelLevel;
      SegmentCategory = _vars.SegmentCategory;
      RatePlanCode = $btn.data('ratePlanCode');
      GuestPerRoom = _vars.requestParams.GuestPerRoom;
      return {
        HotelID: HotelID,
        HallIDs: HallIDs,
        CheckInDate: CheckInDate,
        CheckOutDate: CheckOutDate,
        ActivityID: ActivityID,
        RoomType: RoomType,
        BookingType: BookingType,
        RatePlanCode: RatePlanCode,
        HotelLevel: HotelLevel,
        SegmentCategory: SegmentCategory,
        GuestPerRoom: GuestPerRoom,
        RoomCount: RoomCount
      };
    },
    events: {
      'click .orderbtn': 'orderHandler',
      'click .more': 'moreInfoHandler',
      'click .close': 'closeMoreInfoHandler',
      'click .queryroomtype': 'refreshRoomTypeOversea',
      'click .moreprice': 'morePriceHandler',
      'click .viewallprice': 'allPriceHandler',
      'mouseenter .exchangeArea': 'showExchangeAreaHandler',
      'mouseleave .exchangeArea': 'hideExchangeAreaHandler'
    },
    updateCheckInDay: function(checkin) {
      HotelDetailRoomBase.prototype.updateCheckInDay.apply(this, arguments);
      return _vars.checkindays = checkin.checkInDays;
    },
    refreshRoomTypeOversea: function(e) {
      this.updateGuestPerRoom();
      return HotelDetailRoomBase.prototype.refreshRoomType.apply(this, arguments);
    },
    showExchangeAreaHandler: function(e) {
      var target;
      target = $(e.currentTarget);
      return target.find('.exchangePopup').show();
    },
    hideExchangeAreaHandler: function(e) {
      var target;
      target = $(e.currentTarget);
      return target.find('.exchangePopup').hide();
    },
    updateGuestPerRoom: function() {
      _vars.requestParams.GuestPerRoom = +this.$el.find('.numberinput').val() || 1;
    },
    morePriceHandler: function(e) {
      var $self, index, roomexpands, roomtd, rowspan;
      $self = $(e.currentTarget);
      index = $self.data('index');
      rowspan = $self.data('rowspan');
      if (index && rowspan) {
        roomexpands = this.$el.find('.room.expand' + index);
        roomtd = this.$el.find('.roomindex' + index + ' .roomtd');
        if ($self.data('visible') === 'visible') {
          $self.data('visible', null);
          roomexpands.addClass('Ldn');
          roomtd.attr('rowspan', 1);
          $self.find('span').text('');
          $self.find('.arrow1').removeClass('reverse');
          $self.removeClass('active');
        } else {
          $self.data('visible', 'visible');
          roomexpands.removeClass('Ldn');
          roomtd.attr('rowspan', rowspan);
          $self.find('span').text('收起');
          $self.find('.arrow1').addClass('reverse');
          $self.addClass('active');
        }
      }
    },
    allPriceHandler: function(e) {
      var $self, morepriceboxhide, roomhide;
      $self = $(e.currentTarget);
      roomhide = this.$el.find('.roomhide');
      morepriceboxhide = this.$el.find('.morepriceboxhide');
      if ($self.data('visible') === 'visible') {
        this.$el.find('.morepriceboxhide .moreprice.active').trigger('click');
        setTimeout(function() {
          $self.data('visible', null);
          morepriceboxhide.addClass('Ldn');
          roomhide.addClass('Ldn');
          $self.find('span').text('查看');
          return $self.find('.arrow1').removeClass('reverse');
        }, 0);
      } else {
        $self.data('visible', 'visible');
        morepriceboxhide.removeClass('Ldn');
        roomhide.removeClass('Ldn');
        $self.find('span').text('收起');
        $self.find('.arrow1').addClass('reverse');
      }
    }
  });


  /*}}} */

  if (_stor('HOTELTYPE') === 'oversea') {
    __hotelDetailRoomTemplate = 'HotelDetailRoomTypeOversea';
    __hotelDetailRoomDepend = 'HotelDetailRoomTypeOverseaTemplate';
    __hotelDetailRoomModel = HotelDetailRoomOverseaModel;
    __hotelDetailRoomView = HotelDetailRoomOversea;
  } else {
    __hotelDetailRoomTemplate = 'HotelDetailRoomType';
    __hotelDetailRoomDepend = 'HotelDetailRoomTypeTemplate';
    __hotelDetailRoomModel = HotelDetailRoomModel;
    __hotelDetailRoomView = HotelDetailRoom;
  }


  /*[block.hotelDetailRoom] 酒店详情房型块{{{ */

  _n.block('block.hotelDetailRoom', {
    depend: __hotelDetailRoomDepend,
    init: function(elem, params) {
      return new __hotelDetailRoomView({
        el: elem,
        $el: $(elem),
        model: new __hotelDetailRoomModel()
      });
    }
  });


  /*}}} */


  /*[ui.loading] 全局loding {{{ */

  HotelLoading = Backbone.View.extend({
    render: function(show) {
      var $html, html;
      html = this.template({});
      $html = $(html);
      $html.appendTo('body');
      this.el = this.$el = $html;
      if (show) {
        this.$el.show();
      }
    },
    show: function(type, callback) {
      if (this.$el) {
        this.$el.show();
      } else {
        this.render(true);
      }
      if (callback) {
        callback();
      }
    },
    hide: function(callback) {
      this.showToken = '';
      if (this.$el) {
        this.$el.hide();
      }
      if (callback) {
        callback();
      }
    },
    constructor: function(option) {
      Backbone.View.apply(this, arguments);
      this.template = _func.getTemplate('HotelCommonLoading');
      this.el = this.$el = null;
      _n.on('showLoading', _.bind(this.show, this));
      _n.on('hideLoading', _.bind(this.hide, this));
    }
  });

  _n.block('ui.loading', {
    init: function(elem, params) {
      return new HotelLoading();
    }
  });


  /*}}} */


  /*[block.hotelListFilter] 酒店列表筛选功能{{{ */

  HotelListFilterModel = Backbone.Model.extend({
    set: function(key, val, option) {
      Backbone.Model.prototype.set.apply(this, arguments);
      if (_.isObject(key)) {
        return;
      }
      if (!option || !option.unset) {
        this.trigger('setParam', key);
        HZWeb.search.setParam(key, val);
        _n.trigger('fetchHotelList', 'filterChange');
      }
    },
    unset: function(key) {
      Backbone.Model.prototype.unset.apply(this, arguments);
      this.trigger('unsetParam', key);
      HZWeb.search.removeParam(key);
      _n.trigger('fetchHotelList', 'filterChange');
    }
  });

  HotelListFilterView = Backbone.View.extend({
    positionSwitchHandler: function(e) {
      var $posbox, $self, index;
      $self = $(e.currentTarget);
      if (!$self.hasClass('active')) {
        $self.siblings('.active').removeClass('active');
        $self.addClass('active');
        index = $self.index();
        $posbox = $self.parents('.filteritem').next();
        $('.posexpand', $posbox).hide().eq(index - 1).show();
        this.showExpand();
      }
    },
    moreHandler: function(e) {
      var $content, $self;
      $self = $(e.currentTarget);
      $content = $self.siblings('.contentbox');
      if ($content.hasClass('show')) {
        $content.removeClass('show');
        $self.removeClass('reverse');
        $self.find('span').text('展开');
      } else {
        $content.addClass('show');
        $self.addClass('reverse');
        $self.find('span').text('收起');
      }
    },
    checkHandler: function(e) {
      var $checked, $itembox, $self, check, checkedId, i, key, len, paramName, valueName;
      $self = $(e.currentTarget);
      $itembox = $self.parent().parent();
      if ($itembox.hasClass('content')) {
        $('#Plist_filter .posexpand:hidden .check1:checked').prop('checked', false);
      }
      paramName = $itembox.data('param');
      $checked = $itembox.find('.check1:checked');
      checkedId = [];
      valueName = 'searchCode';
      if ($itembox.hasClass('content')) {
        valueName = 'areaCode';
      }
      for (key = i = 0, len = $checked.length; i < len; key = ++i) {
        check = $checked[key];
        checkedId.push($(check).data(valueName));
      }
      if (checkedId.length) {
        checkedId = checkedId.join(',');
        this.model.set(paramName, checkedId);
      } else {
        this.model.unset(paramName);
      }
    },
    cleanHandler: function(e) {
      var $checked, $itembox, paramName;
      $itembox = $(e.currentTarget).parent();
      if ($itembox.hasClass('positem')) {
        $checked = $itembox.parents('.filteritem').siblings('.posbox').find('input.check1:checked');
      } else {
        $checked = $itembox.find('input.check1:checked');
      }

      /*clear */
      if ($checked.length) {
        $checked.prop('checked', false);
        paramName = $itembox.data('param');
        this.model.unset(paramName);
      }
    },
    paramChangeHandler: function(key, type) {
      var $clean;
      if (key === 'AreaCode') {
        $clean = this.$('.positem .clean');
      } else if (key === 'HotelStyleList') {
        $clean = this.$('.branditem .clean');
      } else if (key === 'PriceRange') {
        $clean = this.$('.priceitem .clean');
      } else if (key === 'ActivityID') {
        $clean = this.$('.activityitem .clean');
      } else if (key === 'FacilityList') {
        $clean = this.$('.serviceitem .clean');
      } else if (key === 'UserOptimization') {
        $clean = this.$('.commentitem .clean');
      }
      if ($clean) {
        if (type === 'set') {
          $clean.addClass('enable');
        } else if (type === 'del') {
          $clean.removeClass('enable');
        }
      }
    },

    /**
     * 直接从数据中载入搜索条件 add by fsy0718 at 2015/10/12
     * @param  {Object} data
     */
    checkParamFromData: function(data) {
      var filterSelectorMaps, hasChangeFilterVal, self;
      self = this;
      filterSelectorMaps = {
        'AreaCode': '.posbox',
        'HotelStyleList': '.branditem',
        'PriceRange': '.priceitem',
        'ActivityID': '.activityitem'
      };
      hasChangeFilterVal = false;
      _.each(data.data, function(filterVal, filterKey) {
        var _filterVal, context, selector;
        if (filterVal) {
          hasChangeFilterVal = true;
          _filterVal = [];
          if (_.isArray(filterVal)) {
            _filterVal = _filterVal.concat(filterVal);
          } else if (_.isString(filterVal)) {
            _filterVal = _filterVal.concat(filterVal.split(','));
          }
          selector = filterKey === 'AreaCode' && 'data-area-code' || 'data-search-code';
          context = self.$(filterSelectorMaps[filterKey] + ' .check1');
          _.each(_filterVal, function(val) {
            return self.checkParamItem(filterKey, val, selector, context);
          });
          return true;
        }
      });
      _.isFunction(data.callback) && data.callback(hasChangeFilterVal, data, self);
      return hasChangeFilterVal = false;
    },
    checkParamItem: function(key, val, selector, context) {
      context.filter('[' + selector + '=' + val + ']').prop('checked', 'checked');
      return this.paramChangeHandler(key, 'set');
    },
    expandHandler: function(e) {
      var $self;
      $self = $(e.currentTarget);
      if ($self.data('expand') !== 'shrink') {
        $('#Plist_filter .filteritem:gt(2)').hide();
        $self.data('expand', 'shrink');
        $self.addClass('shrink');
      } else {
        $('#Plist_filter .filteritem:gt(2)').show();
        $self.data('expand', '');
        $self.removeClass('shrink');
      }
    },
    showExpand: function() {
      this.$('.content:visible').each(function() {
        var $self, height;
        $self = $(this);
        height = $self.height();
        if (height && height > 72) {
          return $self.parent().siblings('.more').show();
        }
      });
    },
    filterExpand: function() {
      var $active, $expand, $service;
      $expand = this.$('.expand');
      $active = this.$('.activityitem');
      $service = this.$('.serviceitem');
      if (!$active.length && !$service.length) {
        $expand.hide();
      } else {
        $expand.trigger('click');
      }
    },
    events: {
      'click .positem .item': 'positionSwitchHandler',
      'click .clean': 'cleanHandler',
      'click .check1': 'checkHandler',
      'click .more': 'moreHandler',
      'click .expand': 'expandHandler'
    },
    constructor: function(option) {
      Backbone.View.apply(this, arguments);

      /*clean高亮，通过侦听param实现 */
      this.listenTo(this.model, 'change');
      this.listenTo(this.model, 'setParam', function(key) {
        return this.paramChangeHandler(key, 'set');
      });
      this.listenTo(this.model, 'unsetParam', function(key) {
        return this.paramChangeHandler(key, 'del');
      });

      /*位置筛选项展开 */
      this.showExpand();

      /*筛选项展开 */
      this.filterExpand();

      /*添加有默认搜索条件数据的监听函数 add by fsy0718 */
      _n.on('HotelListFilterChangeFromData', _.bind(this.checkParamFromData, this));
    }
  });

  _n.block('block.hotelListFilter', {
    init: function(elem, params) {
      return new HotelListFilterView({
        el: elem,
        $el: $(elem),
        model: new HotelListFilterModel()
      });
    }
  });


  /*}}} */


  /*[block.hotelUserInfo] 用户信息{{{ */

  HotelUserSignInPopup = Backbone.View.extend({
    postMessageCallback: function(e) {
      var data;
      data = e.data;
      if (typeof data === 'string') {
        data = $.parseJSON(data);
      }
      if (data.STToken) {
        HZWeb.user.trigger('userSignInPopupComplete', data.STToken || '');
      }
      this.hide();
    },
    setIframeUrl: function(url) {
      this.$('iframe').attr('src', url || _vars.signInPopupUrl);
    },
    render: function() {
      var html;
      if (window.addEventListener) {
        window.addEventListener('message', _.bind(this.postMessageCallback, this));
      } else if (window.attachEvent) {
        window.attachEvent('onmessage', _.bind(this.postMessageCallback, this));
      }
      html = this.template({});
      this.el = this.$el = $(html);
      this.delegateEvents();
      this.$el.appendTo('body');
      this.$el.show();
    },
    show: function() {
      if (!this.$el) {
        this.render();
      }
      this.$el.show();
      this.setIframeUrl();
    },
    hide: function() {
      if (this.$el.length) {
        this.$el.hide();
      }
    },
    closeHandler: function(e) {
      this.$el.hide();
      HZWeb.user.trigger('userSignInPopupCancel');
    },
    events: {
      'click .close': 'closeHandler'
    },
    constructor: function() {
      Backbone.View.apply(this, arguments);
      this.el = this.$el = '';
      this.template = _func.getTemplate('userSignInTemplate');
      this.listenTo(HZWeb.user, 'userSignInPopup', this.show);
      this.listenTo(HZWeb.user, 'USER_SIGNIN', this.hide());
    }
  });

  HotelUserInfo = Backbone.View.extend({
    constructor: function() {
      Backbone.View.apply(this, arguments);
      this.signInPopup = new HotelUserSignInPopup();
    }
  });

  _n.block('block.hotelUserInfo', {
    init: function(elem, params) {
      return new HotelUserInfo({
        el: elem,
        $el: $(elem)
      });
    }
  });

  HeadUserInfo = Backbone.View.extend({
    render: function() {
      var MemberName, SignInUrl, SignOutUrl, SignUpUrl, html, redirectUrl;
      MemberName = HZWeb.user.getMemberName();
      redirectUrl = encodeURIComponent(location.href.replace(/#.*$/, ''));
      SignInUrl = _vars.signInUrl + redirectUrl;
      SignOutUrl = _vars.signOutUrl + redirectUrl;
      SignUpUrl = _vars.signUpUrl + redirectUrl;
      html = this.template({
        MemberName: MemberName,
        SignInUrl: SignInUrl,
        SignOutUrl: SignOutUrl,
        SignUpUrl: SignUpUrl
      });
      this.$el.html(html);
      this.delegateEvents();
    },

    /*登录 */
    signinHandler: function(e) {
      HZWeb.user.signIn();
    },

    /*退出 */
    signoutHandler: function(e) {
      HZWeb.user.signOut();
    },

    /*注册 */
    signupHandler: function(e) {
      HZWeb.user.signUp();
    },
    accounthandler: function(e) {
      if (HZWeb.user.hasSigned()) {
        return HZWeb.user.goHome();
      } else {
        return HZWeb.user.signIn();
      }
    },
    events: {
      'click .myaccount': 'accounthandler'
    },
    constructor: function() {
      Backbone.View.apply(this, arguments);
      // this.template = _func.getTemplate('userInfoTemplate');
      _n.on('USER_SIGNIN', _.bind(this.render, this));
      _n.on('USER_SIGNOUT', _.bind(this.render, this));
    }
  });

  _n.block('block.headUserInfo', {
    init: function(elem, params) {
      return new HeadUserInfo({
        el: elem,
        $el: $(elem)
      });
    }
  });


  /*}}} */


  /*[ui.error] 全局error{{{ */

  HotelError = Backbone.View.extend({
    render: function(show, message) {
      var $html, html;
      if (message == null) {
        message = '';
      }
      html = this.template({
        message: message
      });
      $html = $(html);
      $html.appendTo('body');
      this.el = this.$el = $html;
      this.delegateEvents();
      if (show) {
        this.$el.show();
      }
    },
    show: function(msg) {
      if (this.$el) {
        this.$el.find('error_intro').html(msg);
        this.$el.show();
      } else {
        this.render(true, msg);
      }
    },
    hide: function() {
      if (this.$el) {
        this.$el.hide();
      }
    },
    events: {
      'click .close': 'hide'
    },
    constructor: function(option) {
      Backbone.View.apply(this, arguments);
      this.template = _func.getTemplate('HotelCommonError');
      this.el = this.$el = null;
      _n.on('showError', _.bind(this.show, this));
      _n.on('hideError', _.bind(this.hide, this));
    }
  });

  _n.block('ui.error', {
    init: function(elem, params) {
      return new HotelError();
    }
  });


  /*}}} */


  /*[block.trackCompatibleMode] {{{ */

  TrackCompatibleMode = (function() {
    TrackCompatibleMode.prototype.maxTryCount = 100;

    TrackCompatibleMode.prototype.tryTimeSpan = 100;

    TrackCompatibleMode.prototype.setTrackEvent = function() {
      if (this.count < this.maxTryCount) {
        this.count++;
        if (typeof wa_track_event === 'function') {
          if (this.compatibleMode) {
            return wa_track_event('开发者', '追踪兼容性视图', '兼容性视图', 1);
          } else {
            return wa_track_event('开发者', '追踪兼容性视图', '非兼容性视图', 1);
          }
        } else {
          return setTimeout(_.bind(this.setTrackEvent, this), this.tryTimeSpan);
        }
      }
    };

    function TrackCompatibleMode() {
      this.count = 0;
      if (document.documentMode && parseInt(document.documentMode) < 8) {
        this.compatibleMode = true;
      } else {
        this.compatibleMode = false;
      }
      this.setTrackEvent();
    }

    return TrackCompatibleMode;

  })();

  TrackCompatibleMode.init = function(elem, params) {
    return new TrackCompatibleMode();
  };

  _n.block('block.trackCompatibleMode', TrackCompatibleMode);


  /*}}} */

}).call(this);
